package com.yami.shop.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.common.util.PageParam;

import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.yami.shop.service.JiaoyouOrderService;
import com.yami.shop.bean.model.JiaoyouOrder;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

/**
 * <p>
 * 订单表 充值或购买vip 前端控制器
 * </p>
 *
 * @author chajiu
 * @since 2021-07-14
 */
@RestController
@RequestMapping("/futong-order")
public class JiaoyouOrderController {


    @Autowired
    private JiaoyouOrderService JiaoyouOrderService;


    /**
     * 分页获取
    */
     @GetMapping("/page")
     @PreAuthorize("@pms.hasPermission('admin:FutongOrder:page')")
     public ResponseEntity<IPage<JiaoyouOrder>> page(JiaoyouOrder entity, PageParam<JiaoyouOrder> page) {
         IPage<JiaoyouOrder> iPage = JiaoyouOrderService.page(page, new LambdaQueryWrapper<JiaoyouOrder>());
         return ResponseEntity.ok(iPage);
     }

    /**
     * 保存
     */
    @PostMapping("/save")
    @PreAuthorize("@pms.hasPermission('admin:FutongOrder:save')")
    public ResponseEntity<Void> save(@RequestBody JiaoyouOrder entity) {
        JiaoyouOrderService.save(entity);
        return ResponseEntity.ok().build();
    }

    /**
     * 获取信息
     */
    @GetMapping("/info/{id}")
    @PreAuthorize("@pms.hasPermission('admin:FutongOrder:info')")
    public ResponseEntity<JiaoyouOrder> info(@PathVariable("id") String id){
        JiaoyouOrder entity = JiaoyouOrderService.getById(id);
            return ResponseEntity.ok(entity);
    }

    /**
     * 修改
     */
    @PutMapping
    @PreAuthorize("@pms.hasPermission('admin:FutongOrder:update')")
    public ResponseEntity<Void> update(@RequestBody JiaoyouOrder entity){
        JiaoyouOrderService.updateById(entity);
            return ResponseEntity.ok().build();
    }

    /**
     * 删除
     */
    @DeleteMapping
    @PreAuthorize("@pms.hasPermission('admin:FutongOrder:delete')")
    public ResponseEntity<Void> delete(@RequestBody String[]ids){
        JiaoyouOrderService.removeByIds(Arrays.asList(ids));
            return ResponseEntity.ok().build();
    }


}

